home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 928 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.1 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Quick questions (but no longer so quic
  5. Date: 01 Apr 1996 10:42:24 PST
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4jp6jf$lbj@engnews1.Eng.Sun.COM>
  9. References: <4jnip5$916@mule2.mindspring.com>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 1 Apr 1996 18:17:19 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMWAjkUy4NqrwXLNJAQGzpQH/YLF14KNzTX8N9kUnNO0xs9LqJOUeBieX
  15.     logLbpzLGCrE5zUqCzzon8UstxaWHigJrf+1XZSQYBQKX1eQxp6zug==
  16.     =+3hT
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article 916@mule2.mindspring.com, abell@mindspring.com (Andrew Bell) writes:
  20. >clamage@Eng.Sun.COM (Steve Clamage) wrote:
  21. >>C++ implementations don't exist in a vacuum. They
  22. >>have to coexist with platform ABIs (Application Binary Interface, the
  23. >>bit-level description of data and function calls). It is common for an ABI
  24. >>to specify rules for structured types that are different from the rules
  25. >>for simple types, no matter what the contents of the structure. 
  26.  
  27. >But where would our example [ class Short { int short; }; ] ever need
  28. >to appear as anything other than a short, save within the C++ program
  29. >itself?  
  30.  
  31. >>Either the generated code is incompatible with system and 3rd-party
  32. >>libraries, or the compiler violates the C++ standard.
  33.  
  34. >Given that name-mangling isn't standard or consistent from compiler to
  35. >compiler, unless you have a library created by that same compiler
  36. >(that would thus realize the alignment would be as per short), when
  37. >would this matter? 
  38.  
  39. That isn't a given, it is a lamentable state of affairs which many vendors
  40. are laboring to fix. Because C++ implementations are usually mutually
  41. incompatible even on the same platform, implementors are careful to use
  42. different name mangling to reduce the chance of linking together code
  43. which won't run properly together. In other words, object code is not
  44. incompatible because of differences in name mangling; rather, name
  45. mangling schemes are different because object code is incompatible anyway.
  46.  
  47. By definition, if you have a platform ABI, object code (including name
  48. mangling) is consistent across implementations and languages. The
  49. whole point of an ABI is that you can write code in one language
  50. compiled with one compiler, and link it with code from another language
  51. and/or compiler.
  52.  
  53. If ABIs that include C++ are to become a reality, and they must for C++
  54. to be successful, the standard must not constrain implementations to
  55. the point where they cannot conform to platform ABIs.
  56.  
  57. You are asking in this thread to be able to extend a class and keep
  58. guarantees about its layout and structure, and keep a simple class like
  59. Short bit-compatible with type short.
  60.  
  61. Suppose a C programmer writes
  62.     struct Short { short s; };
  63. and your C++ program must link to that code and use struct Short. Further
  64. suppose the ABI for the platform (which has been around for years)
  65. specifies that all structs are aligned on 4-byte boundaries and padded
  66. to 4-byte multiples. (I'm not making up that requirement; it is common.)
  67. In addition, the ABI says that integer types are passed in registers by
  68. value, but all struct types are passed via a pointer and copied by the
  69. called function (also a common requirement).
  70.  
  71. Now suppose the C++ standard says that Short must be treated exactly the
  72. same as short. Boom! It is now impossible to have a C++ compiler that both
  73. complies with the C++ standard and the ABI for that (common) platform. In
  74. my view that is far too high a price to pay for the benefits you want.
  75.  
  76. Nothing prevents an implementation from doing what you want if it is
  77. feasible on the platform. You just can't depend on it in portable code.
  78. ---
  79. Steve Clamage, stephen.clamage@eng.sun.com
  80. ---
  81. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  82.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  83.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  84.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  85.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  86. ]
  87.